import { Component, OnInit } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {DataService} from "../data_service";

@Component({
  selector: 'app-admin',
  templateUrl: './admin.component.html',
  styleUrls: ['./admin.component.css']
})
export class AdminComponent implements OnInit {

  books: any = [];
  categorys: any = [];
  tip="Admin Dashboard"

  constructor(public http: HttpClient, public service: DataService) {
  }

  ngOnInit(): void {
    this.getAllRecord();
    this.getCategorys();
  }


  // getRecord() {
  //   this.service.getData(this.book_ID).subscribe();
  // }

  getAllRecord(category='') {
    this.service.getAllData(category).subscribe(resp => {
      this.books = resp
    });
  }
  removeBook(id:any){
    console.log(id)
    this.service.deleteData(id).subscribe(_=>{
      this.getAllRecord();
    })
  }
  getCategorys() {
    this.service.getCategorys().subscribe(resp => {
      this.categorys = resp
    });
  }
}
